<?php
/* --------------------------------------------------------------
   gm_gprint_cart_actions.php 2009-12-08 mb
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2009 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/
?><?php

	$coo_gm_gprint_product_manager = new GMGPrintProductManager();

	switch($_GET['action'])
	{
		case 'add_product':
			if($coo_gm_gprint_product_manager->get_surfaces_groups_id($_POST['products_id']) !== false)
			{
				$t_products_properties_combis_id = 0;

				if(isset($_POST['properties_values_ids']))
				{
					$coo_properties_control = MainFactory::create_object('PropertiesControl');
					$t_products_properties_combis_id = $coo_properties_control->get_combis_id_by_value_ids_array($_POST['products_id'], $_POST['properties_values_ids']);
					if($t_products_properties_combis_id == 0)
					{
						die('combi not available');
					}
				}

				$t_gm_product = xtc_get_uprid($_POST['products_id'], $_POST['id'], $t_products_properties_combis_id);
				
				if($_POST['submit_target'] == 'cart')
				{
					if(is_object($_SESSION['coo_gprint_cart']))
					{
						$t_new_product = $_SESSION['coo_gprint_cart']->check_cart($t_gm_product, 'cart',  false);
						
						if($t_new_product !== false)
						{
							$t_gm_product = $t_new_product;
						}	
					}
					
					if(isset($_SESSION['cart']->contents[$t_gm_product]))
					{
						$_POST['products_qty'] -= $_SESSION['cart']->contents[$t_gm_product]['qty'];	
						if($_POST['products_qty'] < 0)
						{
							$_POST['products_qty'] = 0;
						}
					}
				}
				elseif($_POST['submit_target'] == 'wishlist')
				{
					if(is_object($_SESSION['coo_gprint_wishlist']))
					{
						$t_new_product = $_SESSION['coo_gprint_wishlist']->check_wishlist($t_gm_product, 'wishList',  false);
				
						if($t_new_product !== false)
						{
							$t_gm_product = $t_new_product;
						}	
					}
					
					if(isset($_SESSION['wishList']->contents[$t_gm_product]))
					{
						$_POST['products_qty'] -= $_SESSION['wishList']->contents[$t_gm_product]['qty'];	
						if($_POST['products_qty'] < 0)
						{
							$_POST['products_qty'] = 0;
						}
					}
				}
			}
							
			break;
		case 'buy_now':
			if($coo_gm_gprint_product_manager->get_surfaces_groups_id($_GET['BUYproducts_id']) !== false)
			{
				if(isset($t_turbo_buy_now) && $t_turbo_buy_now == true)
				{
					$t_show_details = true;
					break;
				}
				if($gmSEOBoost->boost_products) {
					$gm_product_link = $gmSEOBoost->get_boosted_product_url((int)$_GET['BUYproducts_id'], $_GET['gm_boosted_product']);
					xtc_redirect(xtc_href_link($gm_product_link));
				} 
				else
				{
					xtc_redirect(xtc_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int) $_GET['BUYproducts_id'], 'NONSSL'));
				}
			}
			
			break;
	}
	
?>